package com.codeoss.framework.expression;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import com.codeoss.framework.util.StringUtils;

@Service
public class ScriptServiceStore implements IScriptServiceStore,ApplicationContextAware {
	private ApplicationContext applicationContext;
	@Override
	public IScriptService getScriptService(Expression expression) {
		// TODO Auto-generated method stub
		String scriptType=expression.getScriptType();
		if(StringUtils.isEmpty(scriptType)) {
			scriptType="javascript";
		}
		return (IScriptService)applicationContext.getBean(scriptType+"ScriptService");
	}
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		// TODO Auto-generated method stub
		this.applicationContext=applicationContext;
	}

}
